#ifndef PARTICLEFORCEREGISTRY_H
#define PARTICLEFORCEREGISTRY_H

#include "AbstractParticleForceGenerator.h"
#include <vector>


namespace SimPhy
{


/**
  * Holds all the force generators and the particles they apply to.
  */
class ParticleForceRegistry
{
public:
    ParticleForceRegistry();

    /**
     * Registers the given force generator to apply to the
     * given particle.
     */
    void add(Particle* particle, AbstractParticleForceGenerator *forceGenerator);

    /**
     * Removes the given registered pair from the registry.
     * If the pair is not registered, this method will have
     * no effect.
     */
    void remove(Particle* particle, AbstractParticleForceGenerator *forceGenerator);

    /**
     * Clears all registrations from the registry. This will
     * not delete the particles or the force generators
     * themselves, just the records of their connection.
     */
    void clear();

    /**
     * Calls all the force generators to update the forces of
     * their corresponding particles.
     */
    void updateForces(real timeStep);



protected:

    /**
     * Keeps track of one force generator and the particle it
     * applies to.
     */
    struct ParticleForceRegistration
    {
        Particle *m_particle;
        AbstractParticleForceGenerator *m_forceGenerator;
    };

   friend bool operator==(ParticleForceRegistry::ParticleForceRegistration const& r1, ParticleForceRegistry::ParticleForceRegistration const& r2);

    std::vector<ParticleForceRegistration> m_registrations;

};




}

#endif // PARTICLEFORCEREGISTRY_H
